#include "btform.h"
#include "ui_btform.h"

BtForm::BtForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BtForm)
{
    ui->setupUi(this);
    //设置动画效果
    setLineAnimation();
    //隐藏linebox的内容
    ui->lineBox->hide();
    //setStretchFactor(ui->lineBox);
}

BtForm::~BtForm()
{
    delete ui;
}

void BtForm::setIcon(const QString& btIcon, const QString& btText, int mid)
{
    ui->btIcon->setPixmap(QPixmap(btIcon));
    ui->btText->setText(btText);
    this->id = mid;
}

void BtForm::mousePressEvent(QMouseEvent *event)
{
    //通过点击鼠标，改变对应的控件的表现，同时发送信号，通过信号槽的方式改变推荐的内容
    (void)event;    //跳过编译器检查
    //ui->btStyle->setStyleSheet("#btStyle{ background-color:rgb(30,206,154);}*{background-color:#F6F6F6;}");
    ui->btStyle->setStyleSheet("#btStyle{ background-color:rgb(30,206,154);}*{background-color: transparent;}");
    emit click(id);
}

int BtForm::getId()
{
    return this->id;
}

void BtForm::clearBg()
{
    //恢复到原来的颜色
    ui->btStyle->setStyleSheet("#btStyle:hover{ background-color: #D8D8D8;} *{background-color: transparent;}");
}

void BtForm::setLineAnimation()
{
    //设置动画效果步骤：
    //1.创建QPropertyAnimation对象
    //2.设置动画的持续时间
    //3.设置动画的关键帧
    //4.设置动画的循环次数
    //5.开启动画
    //6.动画效果结束会发送finished信号，如果需要对后续进行处理，可以处理这个信号

    lineAnimation1 = new QPropertyAnimation(ui->line1,"geometry",this);
    lineAnimation1->setDuration(1500);
    //这里设置就是从最低到最高再到最低
    lineAnimation1->setKeyValueAt(0,QRect(4,17,2,0));
    lineAnimation1->setKeyValueAt(0.5,QRect(4,0,2,17));
    lineAnimation1->setKeyValueAt(1,QRect(4,17,2,0));
    lineAnimation1->setLoopCount(-1);
    lineAnimation1->start();

    lineAnimation2 = new QPropertyAnimation(ui->line2,"geometry",this);
    lineAnimation2->setDuration(1900);
    lineAnimation2->setKeyValueAt(0,QRect(10,17,2,0));
    lineAnimation2->setKeyValueAt(0.5,QRect(10,0,2,17));
    lineAnimation2->setKeyValueAt(1,QRect(10,17,2,0));
    lineAnimation2->setLoopCount(-1);
    lineAnimation2->start();

    lineAnimation3 = new QPropertyAnimation(ui->line3,"geometry",this);
    lineAnimation3->setDuration(1700);
    lineAnimation3->setKeyValueAt(0,QRect(16,17,2,0));
    lineAnimation3->setKeyValueAt(0.5,QRect(16,0,2,17));
    lineAnimation3->setKeyValueAt(1,QRect(16,17,2,0));
    lineAnimation3->setLoopCount(-1);
    lineAnimation3->start();

    lineAnimation4 = new QPropertyAnimation(ui->line4,"geometry",this);
    lineAnimation4->setDuration(1800);
    lineAnimation4->setKeyValueAt(0,QRect(22,17,2,0));
    lineAnimation4->setKeyValueAt(0.5,QRect(22,0,2,17));
    lineAnimation4->setKeyValueAt(1,QRect(22,17,2,0));
    lineAnimation4->setLoopCount(-1);
    lineAnimation4->start();
}

void BtForm::showAnimal()
{
    ui->lineBox->show();
}
